package com.magicborrow.activity;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

import com.android.volley.VolleyError;
import com.magicborrow.Constants;
import com.magicborrow.R;
import com.magicborrow.beans.ApplyEntity;
import com.magicborrow.utils.UserTools;
import com.magicborrow.utils.VolleyTool;
import com.magicborrow.views.MsgDialog;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by River on 5/6/16.
 */
public class PayoutNoresponseActivity extends BaseActivity implements View.OnClickListener{

    private int id;
    private EditText reason;
    private Button send;
    private ImageButton back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.payout_noresponse_activity);
        id = getIntent().getExtras().getInt("id");
        initView();
        initListener();
    }

    private void initView(){
        reason = (EditText)findViewById(R.id.reason);
        send = (Button)findViewById(R.id.send);
        back = (ImageButton)findViewById(R.id.back);
    }

    private void initListener(){
        reason.setOnClickListener(this);
        send.setOnClickListener(this);
        back.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back:
                finish();
                break;
            case R.id.send:
                String re = reason.getText().toString();
                if("".equals(re)){
                    Toast.makeText(this,"请填写理由",Toast.LENGTH_SHORT).show();
                    return;
                }
                Map<String,String> params = new HashMap<>();
                params.put("id",id+"");
                params.put("reason",re);
                params.put("status","1");
                params.put("acc_token", UserTools.getUser(this).getAcc_token());
                VolleyTool.get(Constants.FLOW_CONTROL, params, new VolleyTool.HTTPListener() {
                    @Override
                    public <T> void onResponse(T t, int requestCode) {
                        try {
                            JSONObject json = new JSONObject(t.toString());
                            int code = json.getInt("code");
                            if(code == 0){
                                Toast.makeText(PayoutNoresponseActivity.this,"申述已发送,请等待平台处理",Toast.LENGTH_SHORT).show();
                                PayoutNoresponseActivity.this.finish();
                            }
                        } catch (JSONException e) {
                            // e.printStackTrace();
                        }
                    }
                    @Override
                    public void onErrorResponse(VolleyError error, int requestCode) {
                        Toast.makeText(PayoutNoresponseActivity.this,"服务器暂时无法链接",Toast.LENGTH_SHORT).show();
                    }
                },0,null);
                break;
        }
    }

}
